package com.briup.recognition.web.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baidu.aip.imageclassify.AipImageClassify;
import com.briup.recognition.api.AipImageClient;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @program:
 * @description: 智能识别接口
 * @author: jacky
 * @create: 2020-10-11 15:51
 **/
@Api(description = "菜品识别相关接口")
@Validated
@RestController
@RequestMapping("/Dishes")
public class DishesRecognitionController {

    @ApiOperation(value = "图像识别")
    @PostMapping("image")
    public void image( @RequestParam("file") MultipartFile file, HttpServletRequest req, HttpServletResponse resp) throws Exception {
        // 获取图像识别客户端
        AipImageClassify client = AipImageClient.getInstance();
//		JSONObject res = client.plantDetect(file.getBytes(), new HashMap<>());
        //JSONObject res = client.advancedGeneral(file.getBytes(), new HashMap<>());
        //JSONObject res = client.flower(file.getBytes(),new HashMap<>());
        //JSONObject res = client.flower(file.getBytes(),new HashMap<>());
        //JSONObject res = client.flower(file.getBytes(), new HashMap<>());
        //JSONObject res = client.ingredient(file.getBytes(), new HashMap<>());
        JSONObject res = client.dishDetect(file.getBytes(), new HashMap<>());
        // 手动返回json
        resp.setHeader("Content-Type", "application/json;charset=UTF-8");
        resp.getWriter().write(res.toString());
    }
}
